from configparser import ConfigParser
import os

class Config(object):
   #初始化cfg
   def __init__(self,config_path='mydb.cnf'):
      file_path=os.path.join(os.path.dirname(__file__),config_path)
      self.cfg=ConfigParser()
      self.cfg.read(filenames=file_path,encoding='utf-8')
    #   print(self.cfg.sections())
    #获取指定key的values
   def getsection(self,section,key):
      return self.cfg.get(section=section,option=key)


if __name__ == '__main__':
    paths=r'myconf.cnf'
    conf=Config(config_path=paths)
    print(conf.getsection(section='mypath',key='read_path'))